package com.yxy.controller;

import com.yxy.base.BusinessException;
import com.yxy.base.Pagingable;
import com.yxy.base.RestResponse;
import com.yxy.dto.TableProjectDto;
import com.yxy.dto.ValidationGroups;
import com.yxy.feign.AuthService;
import com.yxy.model.TableProject;
import com.yxy.utils.TokenCheckUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lixinquan
 * 网点信息
 */
@RestController
@Slf4j
@RequestMapping("/tableProject")
public class TableProjectController {

  @Autowired
  private TokenCheckUtil tokenCheckUtil;

  @Autowired
  private AuthService authService;
  @Autowired
  private com.yxy.service.TableProjectService TableProjectService;

  // 获取列表
  @Pagingable
  @PostMapping("/list")
  public RestResponse<List<TableProject>> getList(@RequestBody TableProjectDto input) throws BusinessException {
    RestResponse<List<TableProject>> restResponse = new RestResponse<>(200, "成功");
    restResponse.setContent(TableProjectService.getlist(input));
    return restResponse;
  }

  // 获取列表
  @PostMapping("/listParent")
  public RestResponse<List<TableProject>> listParent(@RequestBody TableProjectDto input) throws BusinessException {
    RestResponse<List<TableProject>> restResponse = new RestResponse<>(200, "成功");
    restResponse.setContent(TableProjectService.listParent(input));
    return restResponse;
  }


  @GetMapping("/delete")
  public RestResponse<String> deletebaseuser(String idlist, Integer status) throws BusinessException {
    RestResponse<String> restResponse = new RestResponse<>(200, "成功");
    TableProjectService.delete(idlist,status);
    return restResponse;
  }

  //创建与修改
  @PostMapping("/create")
  public RestResponse<TableProject> create(
          @RequestBody @Validated({ValidationGroups.InsertForm.class}) TableProjectDto pojo) throws BusinessException {
    RestResponse<TableProject> restResponse = new RestResponse<>(200, "成功");
    restResponse.setContent(TableProjectService.save(pojo));
    return restResponse;
  }

  //更新数据
  @PutMapping("/update")
  public RestResponse<TableProject> update(
          @RequestBody @Validated({ValidationGroups.UpdateForm.class}) TableProjectDto pojo) throws BusinessException {
    RestResponse<TableProject> restResponse = new RestResponse<>(200, "成功");
    restResponse.setContent(TableProjectService.modify(pojo));
    return restResponse;
  }








}
